import 'package:flutter/material.dart';
import 'package:wx_faxian/pages/discover/child_page.dart';

class DiscoverCell extends StatefulWidget {
  String title;
  String? subTitle;
  String imageName;
  String? subImageName;

  DiscoverCell({
    super.key,
    required this.title,
    this.subTitle,
    required this.imageName,
    this.subImageName,
  });

  @override
  State<DiscoverCell> createState() => _DiscoverCellState();
}

class _DiscoverCellState extends State<DiscoverCell> {
  Color _bgColor = Colors.white;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        // 跳转到子页面
        Navigator.of(context).push(MaterialPageRoute(
          builder: (context) => DiscoverChildPage(title: widget.title),
        ));
        _bgColor = Colors.white;
      },
      onTapDown: (details) {
        setState(() {
          _bgColor = Colors.grey;
        });
      },
      onTapCancel: () {
        setState(() {
          _bgColor = Colors.white;
        });
      },
      child: Container(
        height: 45,
        padding: const EdgeInsets.fromLTRB(0, 0, 10, 0),
        color: _bgColor,
        child: Row(
          // 水平方向排列方式
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Container(
              padding: const EdgeInsets.all(10),
              child: Row(
                children: [
                  Image(image: AssetImage(widget.imageName), width: 20),
                  const SizedBox(width: 15),
                  Text(widget.title)
                ],
              ),
            ),
            Container(
              alignment: Alignment.center,
              child: Row(
                children: [
                  Text(widget.subTitle ?? ''),
                  widget.subImageName != null
                      ? const Icon(Icons.circle, size: 12, color: Colors.red)
                      : Container(),
                  const Icon(Icons.arrow_forward_ios, size: 15),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
